import 'package:boss/models/sku.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusCommodityByFormField/page/skuSetting/provider/sku_provider.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'sku_card.dart';
import 'sku_footer.dart';
import 'sku_plus_btn.dart';

class SkuBrowser extends StatefulWidget {
  final List<Sku> skus;

  const SkuBrowser({Key key, this.skus}) : super(key: key);

  @override
  _SkuBrowserState createState() => _SkuBrowserState();
}

class _SkuBrowserState extends State<SkuBrowser> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: SingleChildScrollView(
            padding: EdgeInsets.symmetric(
              vertical: 20.w,
              horizontal: 30.w,
            ),
            child: Consumer<SkuProvider>(
              builder: (context, skuProvider, child) {
                List<Widget> children = [];
                skuProvider.skus.forEach((sku) {
                  var index = skuProvider.skus.indexOf(sku);

                  children.add(SkuCard(
                    key: sku.key,
                    data: sku,
                    index: index,
                  ));
                });

                children.add(SkuPlusBtn());

                return Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: children,
                );
              },
            ),
          ),
        ),
        SkuFooter(),
      ],
    );
  }
}
